{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Simulate molecular ground state with quantum algorithms\n",
    "\n",
    "In this example, we'll simulate the molecular ground state of caffeine and hydrogen (H2) using Quantum Phase Estimation (QPE) and Variational Quantum Eigensolver (VQE). We'll show how many quantum resources (qubits, gates) the different approaches require and run the results on a quantum simulator.\n",
    "\n",
    "To read more about these two algorithms, take a look at our blog post on the Q# Dev blog: [Quantum developer tools for chemistry](https://devblogs.microsoft.com/qsharp/quantum-developer-tools-for-chemistry/)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/json": "{\"LastUpdated\":\"2021-05-26T07:10:17.958184-07:00\",\"IsCompleted\":false,\"Description\":\"Adding package microsoft.quantum.chemistry.jupyter\",\"Subtask\":null}",
      "text/plain": [
       "Adding package microsoft.quantum.chemistry.jupyter."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/json": "{\"LastUpdated\":\"2021-05-26T07:10:22.440394-07:00\",\"IsCompleted\":false,\"Description\":\"Reloading workspace\",\"Subtask\":null}",
      "text/plain": [
       "Reloading workspace."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import qsharp\n",
    "from qdk.chemistry import Molecule\n",
    "from qdk.chemistry.broombridge import load_and_encode\n",
    "qsharp.reload()\n",
    "from Microsoft.Quantum.Chemistry.QPE import GetEnergyQPE\n",
    "from Microsoft.Quantum.Chemistry.VQE import GetEnergyVQE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. Load molecule"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "caffeine = Molecule.from_xyz(\"../data/xyz/caffeine.xyz\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4f85e9dc05a048a5bf77e3e3948530c8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "JsmolWidget(layout=Layout(align_self='stretch', height='400px'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "caffeine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "102"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "caffeine.num_electrons"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. Load Broombridge and simulate in Q#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "encoded_data_caffeine = load_and_encode(\"../data/broombridge/caffeine.yaml\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. Simulate energy of Caffeine molecule"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2.4 ms, sys: 2.76 ms, total: 5.17 ms\n",
      "Wall time: 850 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "882.6628565016248"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "GetEnergyQPE.simulate(\n",
    "    JWEncodedData=encoded_data_caffeine,\n",
    "    nBitsPrecision=7,\n",
    "    trotterStepSize=0.4,\n",
    "    trotterOrder=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2.86 ms, sys: 4.4 ms, total: 7.26 ms\n",
      "Wall time: 1.78 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'CNOT': 211616,\n",
       " 'QubitClifford': 124794,\n",
       " 'R': 81068,\n",
       " 'Measure': 317,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 5,\n",
       " 'QubitCount': 5,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "resources_caffeine_qpe = GetEnergyQPE.estimate_resources(\n",
    "    JWEncodedData=encoded_data_caffeine, \n",
    "    nBitsPrecision=7,\n",
    "    trotterStepSize=0.4, \n",
    "    trotterOrder=1)\n",
    "resources_caffeine_qpe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. Compare resources to a smaller circuit (VQE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "882.3912532826445"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GetEnergyVQE.simulate(\n",
    "    JWEncodedData=encoded_data_caffeine,\n",
    "    theta1=0.001,\n",
    "    theta2=-0.001,\n",
    "    theta3=0.001,\n",
    "    nSamples=1\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CNOT': 0,\n",
       " 'QubitClifford': 52,\n",
       " 'R': 0,\n",
       " 'Measure': 130,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 4,\n",
       " 'QubitCount': 4,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resources_caffeine_vqe = GetEnergyVQE.estimate_resources(\n",
    "    JWEncodedData=encoded_data_caffeine,\n",
    "    theta1=0.001,\n",
    "    theta2=-0.001,\n",
    "    theta3=0.001,\n",
    "    nSamples=1\n",
    ")\n",
    "resources_caffeine_vqe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Simulate a smaller molecule: H2\n",
    "\n",
    "52 Clifford gates is still a lot of resources, and won't be feasible on near-term hardware. Let's simulate a smaller molecule to compare the required resources to caffeine."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solution did not converge. Lowest energy found: -1.0\n"
     ]
    }
   ],
   "source": [
    "H2 = Molecule.from_smiles(\"[H][H]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0393fd3b566141388e98225f39e06c9e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "JsmolWidget(layout=Layout(align_self='stretch', height='400px'))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "H2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$H_2$ has a much smaller number of electrons than caffeine, as shown below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "H2.num_electrons"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "encoded_data_h2 = load_and_encode(\"../data/broombridge/hydrogen_0.2.yaml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 2.61 ms, sys: 2.18 ms, total: 4.79 ms\n",
      "Wall time: 376 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1.1419413817622361"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "GetEnergyQPE.simulate(\n",
    "    JWEncodedData=encoded_data_h2, \n",
    "    nBitsPrecision=7,\n",
    "    trotterStepSize=0.4,\n",
    "    trotterOrder=1\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CNOT': 99584,\n",
       " 'QubitClifford': 50106,\n",
       " 'R': 43724,\n",
       " 'Measure': 317,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 5,\n",
       " 'QubitCount': 5,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resources_h2_qpe = GetEnergyQPE.estimate_resources(\n",
    "    JWEncodedData=encoded_data_h2, \n",
    "    nBitsPrecision=7,\n",
    "    trotterStepSize=0.4,\n",
    "    trotterOrder=1\n",
    ")\n",
    "resources_h2_qpe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.1166856359999997"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "GetEnergyVQE.simulate(\n",
    "    JWEncodedData=encoded_data_h2, \n",
    "    theta1=0.001,\n",
    "    theta2=-0.001,\n",
    "    theta3=0.001,\n",
    "    nSamples=1\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CNOT': 0,\n",
       " 'QubitClifford': 28,\n",
       " 'R': 0,\n",
       " 'Measure': 70,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 4,\n",
       " 'QubitCount': 4,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resources_h2_vqe = GetEnergyVQE.estimate_resources(\n",
    "    JWEncodedData=encoded_data_h2, \n",
    "    theta1=0.001,\n",
    "    theta2=-0.001,\n",
    "    theta3=0.001,\n",
    "    nSamples=1\n",
    ")\n",
    "resources_h2_vqe"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Comparing resources\n",
    "\n",
    "The below bar chart shows the comparison between number of Clifford gates for the different algorithms as a measure of gate depth for a single quantum program evaluation on both Caffeine and H2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Resources for H2 vs Caffeine')"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgcAAAF1CAYAAAB8o0lsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAArKklEQVR4nO3deZgsZXn38e+PgyCg7CcEWTyoSIK+rgRRE8UlLG4YX1QIEVQiIWo0YhLBqKhoIjFqJMYFA4KGgEiMEIUQRNS8SUBB3AAJBwTPARQEZHFBwfv9o56RrmGmp8/S0+cM38919TXVdz1VdffUTPfdVU89lapCkiRpyjqTTkCSJK1ZLA4kSVKPxYEkSeqxOJAkST0WB5IkqcfiQJIk9VgcSBpZkg2S/FuSW5N8atL5rKnS+ViSW5J8pcX+OMkPktyRZIs5lv9wkjfPT7bSvVkcSCNKcnWSn7Y39+8nOSHJAyad1zzbF9gK2KKqXriqK0uye5LlM8S/mOQP2/RuSc5JcnOSG5N8KsnWq7rtEXLbOslxSa5PcnuS7yR5W5KNRlj8t4HfBbatql2T3A94L7BHVT2gqm4atnBVHVpVR62GlyGtFIsDacU8t6oeADwGeCxwxGTTuUeSd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df5lDR9jW9D4HrxmcmWQnuv4nr6+q/6S70uFNbd7fJFlO94G2PMlb22LHAVskWQocRtcDnuqGhD+V7hvyvwOvqqq7W7+EqeHjL6PrX7K2DB+/MvsKZv7bHuX9aej7UJKnAr9Fd8XBScDPk7yszTuZ7iqmndr+mjpV9y7gd9s2n9meQzdi71V0nZM/SncVylSfoKPoirqvAm9vsYlyhETNKd19Kr5XVUO/fbQPjZPpOuh9bV6S06+Mup/mWMfzgffSdaS8ZnXltiZK8hzgIVV1zBztdgI+B7ymumHZNc9G3VdzrMP3pxVgcSBJkno8rSBJknosDiRJUo/FgSRJ6rE4kCRJPRYHkiSpx+JAkiT1WBxIkqSe/w+8XGqlYcCBVQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 576x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib\n",
    "import pylab as pl\n",
    "%matplotlib inline\n",
    "\n",
    "pl.figure(figsize=(8, 6))\n",
    "pl.bar(\n",
    "    [\n",
    "        \"Caffeine, QPE\",\n",
    "        \"Caffeine, VQE\",\n",
    "        \"H2, QPE x1000\",\n",
    "        \"H2, VQE x1000\",\n",
    "    ],\n",
    "    [\n",
    "        resources_caffeine_qpe[\"QubitClifford\"],\n",
    "        resources_h2_qpe[\"QubitClifford\"],\n",
    "        resources_caffeine_vqe[\"QubitClifford\"] * 1e3,\n",
    "        resources_h2_vqe[\"QubitClifford\"] *  1e3,\n",
    "    ]\n",
    ")\n",
    "pl.ylabel(\"Number of qubit Clifford gates\")\n",
    "pl.title(\"Resources for H2 vs Caffeine\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Estimate ground state\n",
    "\n",
    "The smallest circuit of the 4 aforementioned is VQE on H2. However, it's still quite large and will require some state-of-the-art fine-tuned quantum hardware. To be able to run the sample on hardware, let's try to make it even smaller."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "prepare_state = qsharp.compile(\"\"\"open Microsoft.Quantum.Core;\n",
    "open Microsoft.Quantum.Chemistry;\n",
    "open Microsoft.Quantum.Chemistry.JordanWigner;\n",
    "open Microsoft.Quantum.Chemistry.JordanWigner.VQE;\n",
    "open Microsoft.Quantum.Intrinsic;\n",
    "open Microsoft.Quantum.Diagnostics;\n",
    "\n",
    "operation PrepareStateVQE (JWEncodedData: JordanWignerEncodingData, theta1: Double, theta2: Double, theta3: Double) : Unit {\n",
    "    let (nSpinOrbitals, fermionTermData, inputState, energyOffset) = JWEncodedData!;\n",
    "    let (stateType, JWInputStates) = inputState;\n",
    "    let inputStateParam = (\n",
    "        stateType,\n",
    "        [\n",
    "            JordanWignerInputState((theta1, 0.0), [2, 0]), // singly-excited state\n",
    "            JordanWignerInputState((theta2, 0.0), [3, 1]), // singly-excited state\n",
    "            JordanWignerInputState((theta3, 0.0), [2, 3, 1, 0]), // doubly-excited state\n",
    "            JWInputStates[0] // Hartree-Fock state from Broombridge file\n",
    "        ]\n",
    "    );\n",
    "    use qubits = Qubit[nSpinOrbitals];\n",
    "    PrepareTrialState(inputStateParam, qubits);\n",
    "    DumpRegister((), qubits); // Display the simulated value of the qubit register\n",
    "    ResetAll(qubits);\n",
    "}\"\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prepare the base UCCSD input state"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "qsharp.config[\"dump.basisStateLabelingConvention\"] = \"bitstring\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"div_id\":\"dump-machine-div-cc0a72d5-c660-4d26-ac0e-4a514305fcd0\",\"qubit_ids\":[0,1,2,3],\"n_qubits\":4,\"amplitudes\":[{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.9999985000033751,\"Imaginary\":-5.723123884964407E-17,\"Magnitude\":0.9999985000033751,\"Phase\":-5.723132469643796E-17},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0009999985000033683,\"Imaginary\":-3.5546677115099624E-19,\"Magnitude\":0.0009999985000033683,\"Phase\":-3.554673043507554E-16},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":-0.0009999985000033677,\"Imaginary\":-1.3571111484639956E-19,\"Magnitude\":0.0009999985000033677,\"Phase\":-3.141592653589793},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.000999998500003381,\"Imaginary\":1.639149688420182E-18,\"Magnitude\":0.000999998500003381,\"Phase\":1.639152147142861E-15}]}",
      "text/html": [
       "\r\n",
       "                    <table style=\"table-layout: fixed; width: 100%\">\r\n",
       "                        <thead>\r\n",
       "                            \r\n",
       "                        <tr>\r\n",
       "                            <th>Qubit IDs</th>\r\n",
       "                            <td span=\"3\">0, 1, 2, 3</td>\r\n",
       "                        </tr>\r\n",
       "                    \r\n",
       "                            <tr>\r\n",
       "                                <th style=\"width: 20ch)\">Basis state (bitstring)</th>\r\n",
       "                                <th style=\"width: 20ch\">Amplitude</th><th style=\"width: calc(100% - 26ch - 20ch)\">Meas. Pr.</th><th style=\"width: 6ch\">Phase</th>\r\n",
       "                            </tr>\r\n",
       "                        </thead>\r\n",
       "                        <tbody>\r\n",
       "                        \r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0000\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-ef057e05-1a05-482d-b85d-0b50ae28b42c\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-ef057e05-1a05-482d-b85d-0b50ae28b42c\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0001\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-15a32129-364a-45fe-8198-ea4bda6d0be2\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-15a32129-364a-45fe-8198-ea4bda6d0be2\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0010\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-cb48ad84-1a80-414f-848f-3c9186aa8a5c\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-cb48ad84-1a80-414f-848f-3c9186aa8a5c\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0011\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-0c0e6c8d-a5c3-4af3-8617-f475b7aa0084\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-0c0e6c8d-a5c3-4af3-8617-f475b7aa0084\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0100\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-8513814d-408d-4dc7-84a0-2f5039a6a245\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-8513814d-408d-4dc7-84a0-2f5039a6a245\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0101\\right\\rangle$</td>\r\n",
       "                                <td>$-0.0010  -0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"9.999970000089854E-05\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-4c9d9b2b-597b-4ccb-8e35-102fe9dc196f\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 9.999970000089854E-05;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-4c9d9b2b-597b-4ccb-8e35-102fe9dc196f\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(-180deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0110\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-fc1a2087-0d83-467e-b47e-62eeaca2ce1c\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-fc1a2087-0d83-467e-b47e-62eeaca2ce1c\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0111\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-bf8feb85-d04e-455a-abe6-29534f335eff\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-bf8feb85-d04e-455a-abe6-29534f335eff\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1000\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-9c669fa8-522e-460b-81e3-338cbf2c78f8\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-9c669fa8-522e-460b-81e3-338cbf2c78f8\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1001\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-ac303645-9c70-4817-8c95-4e7356879c2f\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-ac303645-9c70-4817-8c95-4e7356879c2f\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1010\\right\\rangle$</td>\r\n",
       "                                <td>$0.0010  -0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"9.999970000089867E-05\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-e693dfef-826d-4355-a4b5-bb001c5f9701\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 9.999970000089867E-05;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-e693dfef-826d-4355-a4b5-bb001c5f9701\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(-2.036677629419061E-14deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1011\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-2e27b477-4c2f-40b2-9991-a096cdcc31e3\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-2e27b477-4c2f-40b2-9991-a096cdcc31e3\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1100\\right\\rangle$</td>\r\n",
       "                                <td>$1.0000  -0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"99.99970000090002\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-7b9fe7a4-0e8a-4e9b-8227-6890d5cfc680\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 99.99970000090002;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-7b9fe7a4-0e8a-4e9b-8227-6890d5cfc680\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(-3.2791133610487325E-15deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1101\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-c5426a8f-7a57-4e74-b001-48ce750bf60b\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-c5426a8f-7a57-4e74-b001-48ce750bf60b\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1110\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-017e2b32-12a6-42ad-84b1-603b344e1c8b\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-017e2b32-12a6-42ad-84b1-603b344e1c8b\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1111\\right\\rangle$</td>\r\n",
       "                                <td>$0.0010 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"9.999970000090119E-05\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-4df52801-cec3-41b0-8f8c-6c45765148cc\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 9.999970000090119E-05;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-4df52801-cec3-41b0-8f8c-6c45765148cc\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(9.391650001109283E-14deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \r\n",
       "                        </tbody>\r\n",
       "                    </table>"
      ],
      "text/plain": [
       "|0000⟩\t0 + 0𝑖\n",
       "|0001⟩\t0 + 0𝑖\n",
       "|0010⟩\t0 + 0𝑖\n",
       "|0011⟩\t0 + 0𝑖\n",
       "|0100⟩\t0 + 0𝑖\n",
       "|0101⟩\t-0.0009999985000033677 + -1.3571111484639956E-19𝑖\n",
       "|0110⟩\t0 + 0𝑖\n",
       "|0111⟩\t0 + 0𝑖\n",
       "|1000⟩\t0 + 0𝑖\n",
       "|1001⟩\t0 + 0𝑖\n",
       "|1010⟩\t0.0009999985000033683 + -3.5546677115099624E-19𝑖\n",
       "|1011⟩\t0 + 0𝑖\n",
       "|1100⟩\t0.9999985000033751 + -5.723123884964407E-17𝑖\n",
       "|1101⟩\t0 + 0𝑖\n",
       "|1110⟩\t0 + 0𝑖\n",
       "|1111⟩\t0.000999998500003381 + 1.639149688420182E-18𝑖"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prepare_state.simulate(JWEncodedData=encoded_data_h2, theta1=0.001, theta2=-0.001, theta3=0.001, nSamples=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The ground state seems to be very close to |1100>! Let's prepare that state instead."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "prepare_state_simple = qsharp.compile(\"\"\"open Microsoft.Quantum.Core;\n",
    "open Microsoft.Quantum.Chemistry;\n",
    "open Microsoft.Quantum.Chemistry.JordanWigner;\n",
    "open Microsoft.Quantum.Chemistry.JordanWigner.VQE;\n",
    "open Microsoft.Quantum.Intrinsic;\n",
    "open Microsoft.Quantum.Diagnostics;\n",
    "\n",
    "operation PrepareStateVQE (JWEncodedData: JordanWignerEncodingData) : Unit {\n",
    "    let (nSpinOrbitals, fermionTermData, inputState, energyOffset) = JWEncodedData!;\n",
    "    use qubits = Qubit[nSpinOrbitals];\n",
    "    X(qubits[0]);\n",
    "    X(qubits[1]);\n",
    "    DumpRegister((), qubits); // Display the simulated value of the qubit register\n",
    "    ResetAll(qubits);\n",
    "}\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"div_id\":\"dump-machine-div-93d3a0c1-2ddd-4041-b300-c074011a3cf4\",\"qubit_ids\":[0,1,2,3],\"n_qubits\":4,\"amplitudes\":[{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":1.0,\"Imaginary\":0.0,\"Magnitude\":1.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0},{\"Real\":0.0,\"Imaginary\":0.0,\"Magnitude\":0.0,\"Phase\":0.0}]}",
      "text/html": [
       "\r\n",
       "                    <table style=\"table-layout: fixed; width: 100%\">\r\n",
       "                        <thead>\r\n",
       "                            \r\n",
       "                        <tr>\r\n",
       "                            <th>Qubit IDs</th>\r\n",
       "                            <td span=\"3\">0, 1, 2, 3</td>\r\n",
       "                        </tr>\r\n",
       "                    \r\n",
       "                            <tr>\r\n",
       "                                <th style=\"width: 20ch)\">Basis state (bitstring)</th>\r\n",
       "                                <th style=\"width: 20ch\">Amplitude</th><th style=\"width: calc(100% - 26ch - 20ch)\">Meas. Pr.</th><th style=\"width: 6ch\">Phase</th>\r\n",
       "                            </tr>\r\n",
       "                        </thead>\r\n",
       "                        <tbody>\r\n",
       "                        \r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0000\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-7b3e80e0-ead2-4ec6-8b1d-2c82f7239dc6\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-7b3e80e0-ead2-4ec6-8b1d-2c82f7239dc6\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0001\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-0cd0a8d5-1865-465b-b673-f4c5a855d08a\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-0cd0a8d5-1865-465b-b673-f4c5a855d08a\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0010\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-65baf6da-8638-4b4f-9270-0aadd1cfb01d\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-65baf6da-8638-4b4f-9270-0aadd1cfb01d\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0011\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-63bfede3-283b-4afc-8a0d-d93f6bd5cf9d\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-63bfede3-283b-4afc-8a0d-d93f6bd5cf9d\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0100\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-8247fba1-992f-433c-8bbe-abffab2569f9\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-8247fba1-992f-433c-8bbe-abffab2569f9\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0101\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-a2d1524a-ebbb-4fe7-a242-3c524ef186f1\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-a2d1524a-ebbb-4fe7-a242-3c524ef186f1\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0110\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-f1d6989b-d502-4cba-8403-2628ea9d4120\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-f1d6989b-d502-4cba-8403-2628ea9d4120\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|0111\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-7c13db67-7f67-4c41-9255-f9e9d462cce4\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-7c13db67-7f67-4c41-9255-f9e9d462cce4\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1000\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-3d4fa1d3-9172-4158-8e58-e2318750d8c6\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-3d4fa1d3-9172-4158-8e58-e2318750d8c6\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1001\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-3d7eead0-92d6-437f-9a61-810a90bbaafb\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-3d7eead0-92d6-437f-9a61-810a90bbaafb\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1010\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-e12e9ada-b2de-43c8-8a8b-e2387f617189\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-e12e9ada-b2de-43c8-8a8b-e2387f617189\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1011\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-d83cb27f-0828-4d61-bd73-c766578cb509\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-d83cb27f-0828-4d61-bd73-c766578cb509\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1100\\right\\rangle$</td>\r\n",
       "                                <td>$1.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"100\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-0f104d94-595c-41f0-9535-bb92f7fd9e7b\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 100;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-0f104d94-595c-41f0-9535-bb92f7fd9e7b\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1101\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-59071ca3-f1e7-4803-b37d-0175a7dc000b\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-59071ca3-f1e7-4803-b37d-0175a7dc000b\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1110\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-61365996-6e82-40eb-8ae2-7d273c9356e1\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-61365996-6e82-40eb-8ae2-7d273c9356e1\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \n",
       "\r\n",
       "                            <tr>\r\n",
       "                                <td>$\\left|1111\\right\\rangle$</td>\r\n",
       "                                <td>$0.0000 + 0.0000 i$</td>\r\n",
       "                                \r\n",
       "                                <td>\r\n",
       "                                    <progress\r\n",
       "                                        max=\"100\"\r\n",
       "                                        value=\"0\"\r\n",
       "                                        style=\"width: 100%;\"\r\n",
       "                                    > \r\n",
       "                                    <td>\r\n",
       "                                    <p id=\"round-cbb7d090-76fe-4fd7-ac61-4ae0a813ec34\"> \r\n",
       "                                    <script>\r\n",
       "                                    var num = 0;\r\n",
       "                                    num = num.toFixed(4);\r\n",
       "                                    var num_string = num + \"%\";\r\n",
       "                                     document.getElementById(\"round-cbb7d090-76fe-4fd7-ac61-4ae0a813ec34\").innerHTML = num_string;\r\n",
       "                                    </script> </p>\r\n",
       "                                    </td>\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                                \r\n",
       "                                <td style=\"transform: rotate(0deg);\r\n",
       "                   text-align: center;\">\r\n",
       "                                 ↑\r\n",
       "                                </td>\r\n",
       "                            \r\n",
       "                            </tr>\r\n",
       "                        \r\n",
       "                        </tbody>\r\n",
       "                    </table>"
      ],
      "text/plain": [
       "|0000⟩\t0 + 0𝑖\n",
       "|0001⟩\t0 + 0𝑖\n",
       "|0010⟩\t0 + 0𝑖\n",
       "|0011⟩\t0 + 0𝑖\n",
       "|0100⟩\t0 + 0𝑖\n",
       "|0101⟩\t0 + 0𝑖\n",
       "|0110⟩\t0 + 0𝑖\n",
       "|0111⟩\t0 + 0𝑖\n",
       "|1000⟩\t0 + 0𝑖\n",
       "|1001⟩\t0 + 0𝑖\n",
       "|1010⟩\t0 + 0𝑖\n",
       "|1011⟩\t0 + 0𝑖\n",
       "|1100⟩\t1 + 0𝑖\n",
       "|1101⟩\t0 + 0𝑖\n",
       "|1110⟩\t0 + 0𝑖\n",
       "|1111⟩\t0 + 0𝑖"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prepare_state_simple.simulate(JWEncodedData=encoded_data_h2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'CNOT': 0,\n",
       " 'QubitClifford': 2,\n",
       " 'R': 0,\n",
       " 'Measure': 4,\n",
       " 'T': 0,\n",
       " 'Depth': 0,\n",
       " 'Width': 4,\n",
       " 'QubitCount': 4,\n",
       " 'BorrowedWidth': 0}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prepare_state_simple.estimate_resources(JWEncodedData=encoded_data_h2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is much more reasonable to run on near-term hardware. Let's use this ground state preparation to run this sample on real quantum hardware in the next notebook: <a href=\"../Hamiltonian/Approximate Energy using Jordan-Wigner transformation.ipynb\">Hamiltonian/Approximate Energy using Jordan-Wigner transformation.ipynb</a>."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
